﻿@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_Form.cshtml";
}
    <script src="~/lib/uppy/1.16.1/uppy.min.js"></script>
    <script src="~/lib/uppy/1.16.1/zh_CN.min.js"></script>
<link href="~/lib/uppy/1.16.1/uppy.min.css" rel="stylesheet" />
<style>
</style>
<script>
    layui.use(['jquery', 'form', 'laydate', 'tablePlug', 'common'], function () {
        var form = layui.form,
            $ = layui.$,
            common = layui.common,
            laydate = layui.laydate;
        var keyValue = $.request("keyValue");
        //权限字段
        common.authorizeFields('adminform');
        var uppy = Uppy.Core({
            autoProceed: false,
            allowMultipleUploads: false, // 上传完成之后，是否可继续添加文件上传
            addMoreFiles: false,
            restrictions: {
                maxFileSize: 1024 * 1024 * 1024 * 4, // 以字节为单位
                maxNumberOfFiles: 1,
                minNumberOfFiles: 1
                //allowedFileTypes: ['image/*', 'video/*', 'doc/*', 'docx/*', 'xls/*', 'xlsx/*', 'pdf/*'] // mime类型(image/png)或者文件后缀名(.jpg)
            }
        })
            .use(Uppy.Dashboard, {
                id: 'Dashboard',
                metaFields: [
                    // 重命名文件
                    { id: 'name', name: 'Name', placeholder: 'file name' }
                ],
                //theme: 'dark',暗黑模式
                //trigger: '#uppy-select-files',
                target: '#drag-drop-area',
                note: 'image and video only',
                inline: true,
                width: 350,
                height: 250,
                //thumbnailWidth: 280,
                showLinkToFileUploadResult: true,
                showProgressDetails: true,
                hideUploadButton: false,
                hideRetryButton: false,
                hidePauseResumeButton: false,
                hideCancelButton: false,
                hideProgressAfterFinish: false,
                closeModalOnClickOutside: false,
                closeAfterFinish: false,
                disableStatusBar: false,
                disableInformer: false,
                disableThumbnailGenerator: false,
                disablePageScrollWhenModalOpen: true,
                animateOpenClose: true,
                proudlyDisplayPoweredByUppy: true,
                onRequestCloseModal: () => this.closeModal(),
                showSelectedFiles: true,
                locale: Uppy.locales.zh_CN,
                browserBackButtonClose: false
            })
            .use(Uppy.XHRUpload, {
                id: 'XHRUpload',
                endpoint: '/BasicData/Policies/UploadFile',
                method: 'post',
                formData: true,
                fieldName: 'files',
                metaFields: null,
                bundle: true,
                getResponseData(responseText, response) {
                    //debugger
                    //console.log(response)
                    //alert(response.response);
                    $("#F_Content").val(response.response);
                },
                getResponseError(responseText, xhr) {
                    //debugger
                },
                timeout: 30 * 1000, // default 30s
                limit: 0, // Limit the amount of uploads going on at the same time.
                responseType: '', // only '','text','arraybuffer','blob','document'
                locale: {
                    strings: {
                        timeOut: 'upload stalled for %{seconds} seconds, aborting..'
                    }
                }
            })

        uppy.on('file-added', (file) => {
            //uppy.setFileMeta(file)
            uppy.setFileMeta(file.id, {
                size: file.size
            })
        })
        uppy.on('file-removed', (file) => {
            console.log('Removed file', file)
        })
        uppy.on('upload-success', (file, response) => {
            //debugger
        })
        uppy.on('complete', (result) => {
            console.log('Upload complete! We’ve uploaded these files:', result.successful)
        })
        //此处需修改
        //类型为时间时
        //laydate.render({
        //    elem: '#F_Birthday'
        //    , btns: ['clear', 'now']
        //    , trigger: 'click',
        //    format: 'yyyy-MM-dd',
        //});
        function myParamName() {
            returnfiles;
        }
        $(function () {
            initControl();
            if (!!keyValue) {
                common.ajax({
                    url: '/BasicData/Policies/GetFormJson',
                    dataType: 'json',
                    data: { keyValue: keyValue },
                    async: false,
                    success: function (data) {
                        common.val('adminform', data);
                    }
                });
            }
            form.render();
        });
        function initControl() {
            //此处需修改
            //绑定数据源
            //类型为下拉框时
            //上传控件
            //initFileUpload();
        }




        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var postData = data.field;
            common.submitForm({
                url: '/BasicData/Policies/SubmitForm?keyValue=' + keyValue,
                param: postData,
                success: function () {
                    common.parentreload('data-search-btn');
                }
            })
            return false;
        });
    });
</script>

<body>
    <div class="layuimini-container">
        <div class="layuimini-main">
            <div class="layui-form layuimini-form" lay-filter="adminform">
                <div class="layui-form-item layui-hide">
                    <label class="layui-form-label required">标题</label>
                    <div class="layui-input-block">
                        <input type="text" id="F_Title" name="F_Title" autocomplete="off" lay-verify="required" class="layui-input">
                        <input type="hidden" id="F_Content" name="F_Content" autocomplete="off" lay-verify="required" class="layui-input">
                    </div>
                </div>
                <div>
                    <label class="layui-form-label required">上传</label>
                    @*<div class="layui-input-block">
                            <div class="layui-upload-drag" id="test10">
                                <i class="layui-icon"></i>
                                <p>点击上传，或将文件拖拽到此处</p>
                                <div class="layui-hide" id="uploadDemoView">
                                    <hr>
                                    <img src="" alt="上传成功后渲染" style="max-width: 196px">
                                </div>
                            </div>

                        </div>*@
                    <div class="layui-input-block">
                        <div id="drag-drop-area"></div>
                    </div>

                    <div class="layui-form-item layui-hide">
                        <button class="layui-btn" lay-submit id="submit" lay-filter="saveBtn">确认保存</button>
                    </div>
                </div>
            </div>
        </div>
</body>

